package com.shop.controller;

import com.shop.service.DtsGrouponRulesService;
import com.shop.service.DtsGrouponService;
import com.shop.util.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @ClassName AdminGrouponController
 * @Author xiao宋
 * @Date 13:49  2022/10/22
 * @Version 1.0
 * @Description TODO
 */
@Slf4j
@RestController
@RequestMapping("/admin/groupon")
public class AdminGrouponController {
    @Autowired
    DtsGrouponRulesService rulesService;
    @Autowired
    DtsGrouponService grouponService;

    /**
     * 团购规则列表
     *
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @param goodsId 商品 ID
     * @return
     */
    @GetMapping("/list")
    public Object list(
            @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
            @RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit,
            @RequestParam(value = "sort", required = false, defaultValue = "add_time") String sort,
            @RequestParam(value = "order", required = false, defaultValue = "desc") String order,
            Integer goodsId
    ) {
        Map<String, Object> data = rulesService.findByPage(page, limit, sort, order, goodsId);
        return ResponseUtil.ok(data);
    }

    @GetMapping("/listRecord")
    public Object listRecord(
            @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
            @RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit,
            @RequestParam(value = "sort", required = false, defaultValue = "add_time") String sort,
            @RequestParam(value = "order", required = false, defaultValue = "desc") String order,
            Integer rulesId
    ) {
        Map<String, Object> data = grouponService.findByPage(page, limit, sort, order, rulesId);
        return ResponseUtil.ok(data);
    }
}
